package com.zjl.SpringBoot.第21章_流式_响应式_编程.C_Reactive响应式核心;

import org.junit.Test;
import reactor.core.Disposable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;

import java.util.concurrent.atomic.AtomicReference;

public class D6_Flux自己创建序列_多线程 {

    @Test
    public void create() throws Exception {

        Flux.create(fluxSink -> {
            MyListener myListener = new MyListener(fluxSink);
            for (int i = 0; i < 10; i++) {
                myListener.onLine("用户-" + i);
            }
        }).log().subscribe();


        System.in.read();

    }
}

class MyListener {
    FluxSink<Object> sink;

    public MyListener(FluxSink<Object> sink) {
        this.sink = sink;
    }

    public void onLine(String userName) {
        System.out.println("用户登录：" + userName);
        sink.next(userName);
    }
}
